import AlertComponent from './alert.vue'

function createVm (Vue) {
  const Alert = Vue.extend(AlertComponent)
  return new Alert({
    el: document.createElement('div')
  })
}

export default {
  install (Vue) {
    if (!Vue.prototype.$sui) {
      Vue.prototype.$sui = {}
    }

    const vm = createVm(Vue)
    const alert = {
      show ({duration, message, type}) {
        vm.message = message || ''
        vm.duration = duration || 2000
        vm.type = type || 'success'
        vm.isShow = true
      },
      hide () {
        vm.isShow = false
        vm.duration = 2000
        vm.type = 'success'
        vm.message = ''
      }
    }

    Vue.prototype.$sui.$alert = alert
    // Vue.mixin({
    //   created: function () {
    //     this.$sui = Vue.$sui
    //   }
    // })
  }
}
